﻿#region Header Licence
//  NKnobMan, Copyright 2009, Alexandre MUTEL.
// 
//  This is free software; you can redistribute it and/or modify it
//  under the terms of the GNU Lesser General Public License as
//  published by the Free Software Foundation; either version 2.1 of
//  the License, or (at your option) any later version.
// 
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//  Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public
//  License along with this software; if not, write to the Free
//  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
//  02110-1301 USA, or see the FSF site: http://www.fsf.org.
#endregion
using System.Drawing;
using System.Windows.Forms;

namespace NKnobMan.ExportMinimizer
{
    public partial class MainForm : KnobManFormBase
    {
        public MainForm()
        {
            InitializeComponent();
            InitializeFromKnobMan();
        }

        private void InitializeFromKnobMan()
        {
            if (KnobMan != null)
            {
                labelHWND.Text = "Knobman Handle : " + KnobMan.Handle;
                textEditRenderFrames.Text = "" + KnobMan.PrefsRenderFrames;
                textEditOutputSizeX.Text = "" + KnobMan.PrefsOutputSizeX;
                textEditOutputSizeY.Text = "" + KnobMan.PrefsOutputSizeY;
                KnobMan.KnobImageOutput output = KnobMan.CalculateOptimizedExportRenderFramesSize();
                textEditRenderFramesX.Text = "" + output.RenderFramesX;
                textEditRenderFramesY.Text = "" + output.RenderFramesY;
                textEditOutputWidth.Text = "" + output.TotalWidth;
                textEditOutputHeight.Text = "" + output.TotalHeight;
                if (output.RenderFramesX == 1 || output.RenderFramesY == 1)
                {
                    textBoxResult.ForeColor = Color.Maroon;
                    textBoxResult.Text = "RenderFrames are not squarable x*x";

                }
                else
                {
                    textBoxResult.ForeColor = Color.Green;
                    textBoxResult.Text = "Ok";
                }
            }
        }


        private void buttonExport_Click(object sender, System.EventArgs e)
        {
            DialogResult result = saveFileDialog.ShowDialog(this);
            if (result == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;
                KnobMan.ExportOptimizedImage(fileName);
                MessageBox.Show(this, "Exported to " + fileName);
                Close();
            }
        }

        private void buttonCancel_Click(object sender, System.EventArgs e)
        {
            Close();
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            KnobManTraceListenerForm form = new KnobManTraceListenerForm();
            form.Icon = Icon;
            form.Show();
        }
    }
}
